import ajax from '../utils/ajax.js'
import api from '../config/api.js'

import Enum from '../config/enum'

import { globalData } from '@/config/globalData'
import baseUrl from '../baseUrl'

export default class Mall {
  /**
   * 搜索商品分类
   */
  static async getMallClassify (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_MALL_CLASSIFY
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取频道精选
   */
  static async getChannelList () {
    let url = baseUrl.server + api.GET_CHANNEL_LIST
    let res = await ajax.get(url, {
      token: globalData.access_token
    })
    return res
  }

  /**
   * 获取商城楼层列表
   */
  static async getFloorList () {
    let url = baseUrl.server + api.GET_FLOOR_LIST
    let res = await ajax.get(url, {
      token: globalData.access_token
    })
    return res
  }

  /**
   * 获取分类列表
   */
  static async getCateList () {
    let url = baseUrl.server + api.GET_CATE_LIST
    let res = await ajax.get(url, {
      token: globalData.access_token
    })
    return res
  }

  /**
   * 获取分类商品
   */
  static async searchGoods (param = {}) {
    let defParam = {
      token: globalData.access_token,
      page: 1,
      page_size: 20
    }
    let url = baseUrl.server + api.GET_SEARCH_GOODS
    param = Object.assign(defParam, param)
    let res = await ajax.get(url, param)
    return res
  }

  /**
   * 获取专题详情页
   */
  static async getTopicDetail (param = {}) {
    let url = baseUrl.server + api.GET_TOPIC_DETAIL
    let defParam = {
      token: globalData.access_token,
      page_size: 20
    }
    param = Object.assign(defParam, param)
    let res = await ajax.get(url, param)
    return res
  }

  /**
   * 确认下单
   */
  static async confirmOrder (param = {}) {
    let defParam = {
      token: globalData.access_token,
      buy_item: '',
      if_cart: 0
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.ORDER_CONFIRM
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取专题列表
   */
  static async getSpecialList () {
    // let url = baseUrl.server + api.GET_MALL_SPECIAL_LIST;
    // ajax.post(url, {
    //   token: globalData.access_token,
    // }, )
    let url = baseUrl.server + api.GET_ADV
    let res = await ajax.post(url, {
      token: globalData.access_token,
      adv_id: Enum.ADV_TYPE.活动专题广告
    })
    return res
  }

  /**
   * 获取推荐列表
   */
  static async getRecommendlList () {
    let url = baseUrl.server + api.GET_ADV
    let res = await ajax.post(url, {
      token: globalData.access_token,
      adv_id: Enum.ADV_TYPE.单页专题
    })
    return res
  }

  /**
   * 获取专题详情
   */
  static async getSpecialInfo (id) {
    let url = baseUrl.server + api.GET_MALL_SPECIAL_INFO
    let res = await ajax.post(url, {
      topic_id: id,
      token: globalData.access_token
    })
    return res
  }

  /**
   * 获取优惠券列表
   */
  static async getCouponList () {
    let url = baseUrl.server + api.GET_COUPON_LIST
    let res = await ajax.post(url, {
      token: globalData.access_token
    })
    return res
  }

  /**
   * 领取优惠券
   */
  static async getCoupon (id) {
    let url = baseUrl.server + api.GET_COUPON
    let res = await ajax.post(url, {
      coupon_id: id,
      token: globalData.access_token
    })
    return res
  }

  /**
   * 搜索商品
   */
  static async soso (param = {}) {
    let defParam = {
      token: globalData.access_token,
      level: 2,
      page: 1,
      limit: 20
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_MALL_SO_LIST
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 创建订单
   */
  static async createOrder (param = {}) {
    let defParam = {
      token: globalData.access_token,
      buy_item: '',
      if_cart: 0
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.CREATE_MALL_ORDER
    let res = await ajax.post(url, param)
    return res
  }

  // 获取JD库存
  static async getJdInventory (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_GOODS_STOCKS
    let res = await ajax.post(url, param)
    return res
  }

  // 获取JD运费
  static async getJdFreight (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_GOODS_FREIGHT
    let res = await ajax.post(url, param)
    return res
  }

  // 秒杀时间节点
  static async getSeckillTime () {
    let param = {
      token: globalData.access_token
    }
    let url = baseUrl.server + api.GET_SECKILL_TIME
    let res = await ajax.post(url, param)
    return res
  }

  // 获取正在秒杀列表
  static async getSeckillingList () {
    let param = {
      token: globalData.access_token
    }
    let url = baseUrl.server + api.GET_SECKILL_ING_LIST
    let res = await ajax.post(url, param)
    return res
  }

  // 获取正在秒杀列表
  static async getSeckillTimeList (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_SECKILL_TIME_LIST
    let res = await ajax.post(url, param)
    return res
  }

  // 获取秒杀商品详情
  static async getSeckillInfo (activity_id) {
    let param = {
      token: globalData.access_token,
      activity_id: activity_id
    }
    let url = baseUrl.server + api.GET_SECKILL_INFO
    let res = await ajax.post(url, param)
    return res
  }

  // 立即秒杀商品
  static async confirmSeckill (seckill_item) {
    let param = {
      token: globalData.access_token,
      seckill_item: seckill_item
    }
    let url = baseUrl.server + api.GET_SECKILL_SECKILL
    let res = await ajax.post(url, param)
    return res
  }

  static async getGroupList () {
    let param = {
      token: globalData.access_token
    }
    let url = baseUrl.server + api.GET_GROUP_LIST
    let res = await ajax.post(url, param)
    return res
  }

  // 获取拼团商品详情
  static async getGroupInfo (groupbuy_id) {
    let param = {
      token: globalData.access_token,
      groupbuy_id: groupbuy_id
    }
    let url = baseUrl.server + api.GET_GROUP_INFO
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 拼团确认下单
   */
  static async groupConfirmOrder (param = {}) {
    let defParam = {
      token: globalData.access_token,
      groupbuy_id: '',
      member_name: '',
      header_pic: '',
      goods_sku: ''
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_GROUP_CONFIRM_ORDER
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 创建团购订单
   */
  static async createGroupOrder (param = {}) {
    let defParam = {
      token: globalData.access_token,
      groupbuy_id: '',
      member_name: '',
      header_pic: '',
      goods_sku: '',
      address_id: ''
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.CREATE_MALL_GROUP_ORDER
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取分销地址
   */
  static async getShareUrl (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_SHARE_URL
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 京东微GO免登录
   */
  static async getJDUrl (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.JD_NO_LOGIN
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 首页banner 菜单
   */
  static async getNavBanner (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_INDEX_BANNER
    let res = await ajax.get(url, param)
    return res
  }

  /**
   * 获取商品评论统计信息
   */
  static async getCommentInfo (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_COMMENT_INFO
    let res = await ajax.get(url, param)
    return res
  }

  /**
   * 获取商品评论列表
   */
  static async getCommentList (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_COMMENT_LIST
    let res = await ajax.get(url, param)
    return res
  }

  /**
   * 获取商品评论列表
   */
  static async getGoodsNum (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GOODS_NUM
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取商品额度列表
   */
  static async getQuotaList (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.QUATA_LIST
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取商品额度抵扣金额
   */
  static async getQuotaListDetail (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_AMOUNT
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 修改额度密码
   */
  static async changeQuotaPass (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.CHANGE_QUOTA_PASS
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 新秒杀列表
   */
  static async getNewSeckill (param = {}) {
    let url = baseUrl.server + api.NEW_SECKILL
    let res = await ajax.get(url, param)
    return res
  }

  /**
   * 获取视频带货专题列表
   */
  static async getTopicVideoList (param = {}) {
    let url = baseUrl.server + api.GET_TOPIC_VIDEO_LIST
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let res = await ajax.get(url, param)
    return res
  }

  /**
   * 新拼团列表
   */
  static async getNewGroup (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.NEW_GROUP
    let res = await ajax.get(url, param)
    return res
  }

  /**
   * 新优惠券列表
   */
  static async getNewcouponList (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.NEW_COUPON_LIST
    let res = await ajax.get(url, param)
    return res
  }

  /**
   * 新优惠券领取
   */
  static async getNewcoupon (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.NEW_COUPON
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取视频带货专题详情列表
   */
  static async getTopicVideoDetail (param = {}) {
    let url = baseUrl.server + api.GET_TOPIC_VIDEO_DETAIL
    let defParam = {
      token: globalData.access_token,
      page_size: 20
    }
    param = Object.assign(defParam, param)
    let res = await ajax.get(url, param)
    return res
  }
}
